package com.itlong.cloud.operate.resource;

import com.itlong.cloud.POJO.DTO.operate.OperateAppPackageGetPageDTO;
import com.itlong.cloud.POJO.PO.AppPackagePO;
import com.itlong.cloud.POJO.VO.operate.OperateAppPackageGetPageVO;
import com.itlong.cloud.noncore.operate.IOperateAppPackageServiceClient;
import com.itlong.cloud.operate.service.IOperateAppPackageService;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      运营-APP管理-app套餐管理业务处理暴露接口实现类
 * </desc>
 *
 * @createDate 2017/11/01
 */
@RestController
public class OperateAppPackageServiceResource implements IOperateAppPackageServiceClient{
    @Autowired
    IOperateAppPackageService iOperateAppPackageService;

    /**
     * <desc>
     *      保存功能
     * </desc>
     *
     * @param appPackagePO 套餐实体
     * @return sql执行行数
     * @author Jiaqi.X
     * @createDate 2017/11/01
     */
    @Override
    @RequestMapping(path = "/operate/appManage/package/save")
    public String save(@RequestBody AppPackagePO appPackagePO) throws Exception{
        return iOperateAppPackageService.save(appPackagePO);
    }

    /**
     * <desc>
     *      更新功能
     * </desc>
     *
     * @param appPackagePO 套餐实体
     * @return sql执行行数
     * @author Jiaqi.X
     * @createDate 2017/11/01
     */
    @Override
    @RequestMapping(path = "/operate/appManage/package/update")
    public Integer update(@RequestBody AppPackagePO appPackagePO) throws Exception{
        return iOperateAppPackageService.update(appPackagePO);
    }

    /**
     * <desc>
     *      通过id获取功能
     * </desc>
     *
     * @param appPackagePO 套餐实体
     * @return 套餐实体
     * @author Jiaqi.X
     * @createDate 2017/11/01
     */
    @Override
    @RequestMapping(path = "/operate/appManage/package/getOne")
    public AppPackagePO getOne(@RequestBody AppPackagePO appPackagePO){
        return iOperateAppPackageService.getOne(appPackagePO);
    }

    /**
     * <desc>
     *      获取所有套餐
     * </desc>
     *
     * @return 套餐实体集合
     * @author Jiaqi.X
     * @createDate 2017/11/01
     */
    @Override
    @RequestMapping(path = "/operate/appManage/package/getList")
    public List<AppPackagePO> getList(){
        return iOperateAppPackageService.getList();
    }

    /**
     * <desc>
     *      获取分页数据
     * </desc>
     *
     * @param pageDTO 查询参数DTO
     * @return page模型
     * @author Jiaqi.X
     * @createDate 2017/11/01
     */
    @Override
    @RequestMapping(path = "/operate/appManage/package/getPage")
    public Page<OperateAppPackageGetPageVO> getPage(@RequestBody OperateAppPackageGetPageDTO pageDTO) throws Exception{
        return iOperateAppPackageService.getPage(pageDTO);
    }

    /**
     * <desc>
     *      删除功能
     * </desc>
     *
     * @param appPackageIds 套餐id数组
     * @return sql执行行数
     * @author Jiaqi.X
     * @createDate 2017/09/21
     */
    @Override
    @RequestMapping(path = "/operate/appManage/package/delete")
    public Integer delete(@RequestParam("appPackageIds")String appPackageIds){
        return iOperateAppPackageService.delete(appPackageIds);
    }

    /**
     * <desc>
     *      套餐分配功能
     * </desc>
     * @param appFunctionIds 功能id 多个,号分隔
     * @param appPackageId  套餐id
     * @param systemType 系统类型 1app 2小程序 3物业
     * @return
     * @author Jiaqi.X
     * @createDate 2017/11/01
     */
    @Override
    @RequestMapping(path = "/operate/appManage/package/allotFunction")
    public Integer allotFunction(@RequestParam("appFunctionIds") String appFunctionIds,
                                 @RequestParam("appPackageId") String appPackageId,
                                 @RequestParam("systemType") Integer systemType) {
        return iOperateAppPackageService.allotFunction(appFunctionIds,appPackageId,systemType);
    }

    /**
     * <desc>
     *      套餐分配项目
     * </desc>
     *
     * @param appPackageId 套餐id
     * @param allotProjectIds 待分配的项目id
     * @param projectIds 当前页所有项目id
     * @return
     * @author Jiaqi.X
     * @createDate 2017/11/02
     */
    @Override
    @RequestMapping(path = "/operate/appManage/package/allotPackageProject")
    public Integer allotPackageProject(@RequestParam("appPackageId") String appPackageId, @RequestParam("allotProjectIds") String allotProjectIds, @RequestParam("projectIds") String projectIds) throws Exception{
        return iOperateAppPackageService.allotPackageProject(appPackageId,allotProjectIds,projectIds);
    }

    /**
     * <desc>
     *      获取当前套餐已有的项目id集合
     * </desc>
     *
     * @param appPackageId 套餐id
     * @return
     * @author Jiaqi.X
     * @createDate 2017/11/02
     */
    @Override
    @RequestMapping(path = "/operate/appManage/package/getAppPackageProjectIds")
    public List<String> getAppPackageProjectIds(@RequestParam("appPackageId")String appPackageId){
        return iOperateAppPackageService.getAppPackageProjectIds(appPackageId);
    }

    /**
     * <desc>
     *      获取已绑定套餐的项目id
     * </desc>
     *
     * @param appPackageId app套餐id
     * @return
     * @Author Zhu.yj
     * @createDate  2020/4/3
     */
    @PostMapping("/operate/appManage/package/getOtherProjectIds")
    public List<String> getOtherProjectIds(@RequestParam("appPackageId") String appPackageId) throws Exception{
        return iOperateAppPackageService.getOtherProjectIds(appPackageId);
    }

    /**
     * <desc>
     *      根据套餐id获取场景列表
     * </desc>
     *
     * @param appPackageId 套餐
     * @return
     * @Author Zhu.yj
     * @createDate  2021/4/8
     */
    @Override
    @PostMapping("/operate/appManage/package/getSceneIdByPackageId")
    public List<String> getSceneIdByPackageId(@RequestParam("appPackageId") String appPackageId) throws Exception {
        return iOperateAppPackageService.getSceneIdByPackageId(appPackageId);
    }

    /**
     * <desc>
     *      校验项目是否绑定套餐
     * </desc>
     *
     * @param
     * @return
     * @Author Zhu.yj
     * @createDate  2021/5/19
     */
    @PostMapping("/operate/appManage/package/checkProjectsIsBindPackage")
    @Override
    public List<Map<String, Object>> checkProjectsIsBindPackage(@RequestParam("projectIdList") List<String> projectIdList) throws Exception {
        return iOperateAppPackageService.checkProjectsIsBindPackage(projectIdList);
    }

}
